package com.juyu.miliao.api.controller;

import com.juyu.miliao.api.domain.vo.UserSignInInfoVo;
import com.juyu.miliao.api.service.UserSignInService;
import com.juyu.miliao.common.domain.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

/**
 * 用户签到controller
 * @author xuanqicheng
 * @create 2019-12-09:34
 */
@RestController
@RequestMapping("/userSignIn")
public class UserSignInController {

    @Autowired
    private UserSignInService userSignInService;

    /**
     * 判断签到状态
     * @return
     */
    @GetMapping("/status")
    public Object getSignInStatus(){
        return userSignInService.getSignInStatus();
    }

    /**
     * 判断用户签到状态
     * @param token
     * @return
     */
    @GetMapping("/check/signIn")
    public Object checkUserSignIn(Authentication token){
        Subject subject = (Subject) token.getPrincipal();
        return userSignInService.checkUserSignIn(subject.getId());
    }

    /**
     * 获取签到列表
     * @param token
     * @return
     */
    @GetMapping("/list")
    public List<UserSignInInfoVo> getUserSignInList(Authentication token){

        Subject subject = (Subject) token.getPrincipal();

        return userSignInService.getUserSignInList(subject.getId());
    }

    /**
     * 用户签到
     */
    @PostMapping("/")
    public void userSignIn(Authentication token) throws IOException {
        Subject subject = (Subject) token.getPrincipal();
        userSignInService.addUserSignIn(subject.getId());
    }
}
